package com.edu.controller;

import com.edu.entity.Article;
import com.edu.entity.Dict;
import com.edu.service.ArticleService;
import com.edu.vo.ArticleVo;
import com.edu.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName ArticleController
 * @Description
 * @Author W.Jian
 * @Date 2021/5/22 16:02
 **/
@RestController
@RequestMapping("article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;


    @PostMapping("list")
    public Result list(@RequestBody ArticleVo articleVo) {
        return articleService.listByPage(articleVo);
    }

    @PostMapping("listAll")
    public List<Map<String, Object>> listAll(@RequestBody ArticleVo articleVo) {
        return articleService.listByAll(articleVo);
    }


    @PostMapping("saveOrUpdateBatch")
    public Result saveOrUpdateBatch(@RequestBody List<Article> articleList) {
        boolean b = articleService.saveOrUpdateBatch(articleList);
        if (b) {
            return Result.success();
        }
        return Result.failure();
    }

    /**
     * 增加修改
     * @param article
     * @return
     */
    @PostMapping("saveOrUpdateArticle")
    public Result saveOrUpdateArticle(@RequestBody Article article) {
        return articleService.saveOrUpdateWithDict(article);
    }
    @PostMapping("saveOrUpdateArticleA")
    public Result saveOrUpdateArticleA(@RequestBody Article article) {
        return Result.success(articleService.saveOrUpdate(article));
    }

    /**
     * 真删除
     * @param id
     * @return
     */
    @PostMapping("delete")
    public Result delete(Long id){
        return articleService.delete(id);
    }
    /**
     * 假删除
     * @param id
     * @return
     */
    @PostMapping("updateStatus")
    public Result updateStatus(Long id){
        return articleService.updateStatus(id);
    }

    /**
     * 查询详情
     * @param id
     * @return
     */
    @PostMapping("selectById")
    public Result selectById(Long id){
        return articleService.listById(id);
    }

}
